﻿using EFEntity;
using ISerives;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace HRDB.Controllers
{
    public class clientController : Controller
    {
        private readonly Iconfig_majorServices config_majorSerives;
        private readonly Iconfig_major_kindServices config_major_kindSerives;
        private readonly Iconfig_kindServices config_kindSerives; 
        private readonly Iconfig_public_charSerives config_public_charSerives;
        private readonly MyDbContext myDbContext;
        public clientController(Iconfig_majorServices config_majorSerives, 
            Iconfig_major_kindServices config_major_kindSerives, 
            Iconfig_kindServices config_kindSerives, 
            Iconfig_public_charSerives config_public_charSerives,
            MyDbContext myDbContext)
        {
            this.config_majorSerives = config_majorSerives;
            this.config_major_kindSerives = config_major_kindSerives;
            this.config_kindSerives = config_kindSerives;
            this.config_public_charSerives = config_public_charSerives;
            this.myDbContext = myDbContext;
        }
        //职位设置 
        #region
        //查询
        public async Task<IActionResult> major()
        {
            ViewData.Model = await config_majorSerives.Select();
            return View();
        }
        //删除
        public async Task<IActionResult> Del(int id)
        {
            int mun = await config_majorSerives.Delete(id);
            if (mun > 0)
            {
                return RedirectToAction("major");
            }
            else
            {
                return View();
            }
        }
        //添加
        [HttpGet]
        public async Task<IActionResult> major_add()
        {
            ViewBag.s1 = config_majorSerives.idd();
             List<Mconfig_public_char> list = await config_public_charSerives.Select();
            SelectList sl = new SelectList(list, "attribute_name", "attribute_name");
            ViewBag.s2 = sl;
            List<Mconfig_major_kind> list1 = await config_major_kindSerives.Select();
            SelectList sl2 = new SelectList(list1, "major_kind_name", "major_kind_name");
            ViewBag.s = sl2;
            return View();
        }
        //添加
        [HttpPost]
        public async Task<IActionResult> major_add(config_major s)
        {
            s.major_kind_id = myDbContext.ZWFL.Where(e => e.major_kind_name == s.major_kind_name).FirstOrDefault().major_kind_id;
            int num = await config_majorSerives.Add(s);
                if (num > 0)
                {
                    return RedirectToAction("major");
                }
                else
                {
                  
                    return View(s);
                }
           

        }
        #endregion
        //职位分类设置 
        #region
        //查询
        public async Task <IActionResult> major_kind()
        {
            ViewData.Model = await config_major_kindSerives.Select();
            return View();
        }
        //删除
        public async Task<IActionResult> DelKind(int id)
        {
            int mun = await config_major_kindSerives.Delete(id);
            if (mun > 0)
            {
                return RedirectToAction("major_kind");
            }
            else
            {
                return View();
            }
        }
        //添加
        [HttpGet]
        public IActionResult major_kind_add()
        {
            return View();
        }
        //添加
        public async Task<IActionResult> major_kind_add(config_major_kind s)
        {
            if (ModelState.IsValid)
            {
                int num = await config_major_kindSerives.Add(s);
                if (num > 0)
                {
                    return RedirectToAction("major_kind");
                }
                else
                {

                    return View();
                }
            }
            else
            {

                return View();
            }

        }
        #endregion
        //职称名称
        #region
        //查询
        public async Task<IActionResult> profession_design()
        {
            ViewData.Model = await config_public_charSerives.Select();
            return View();
        }
        //删除
        public async Task<IActionResult> profession_designDel(int id)
        {
            int mun = await config_public_charSerives.Delete(id);
            if (mun > 0)
            {
                return RedirectToAction("profession_design");
            }
            else
            {
                return View();
            }
        }
        #endregion
        //下拉框
        private async Task NewMethod()
        {
            //准备下拉框的数据源
            List<Mconfig_public_char> list = await config_public_charSerives.Select();
            SelectList sl = new SelectList(list, "pbc_id", "attribute_name");
            ViewBag.s = sl;

        }

    }
}
